import React from 'react'
import store from '../../store/store'
import {incrementAction,decrementAction,waitIncrementAction} from '../../store/actions/countActions'
import { useDispatch, useSelector} from 'react-redux'


export default function Count (){
    const dispatch = useDispatch()
    const count = useSelector((state)=>state.count.count)
    const movieList =useSelector((state)=>state.movie.movieList)
    const incrementHandle =()=>{
        dispatch(incrementAction(1)) 

      }  

    const decrementHandle =()=>{
        dispatch(decrementAction(1))
      } 
    const ifOddIncrementHandle =()=>{
        if(count%2!=0){
            dispatch(incrementAction(1)) 
        }
    } 
    const waitIncrementHandle =()=>{
        dispatch(waitIncrementAction(1))
    } 



    return (
        <div>
            <h1>我是count组件,我的值是{count}</h1>
            <h2>电影的总数是{movieList.length}</h2>
            <div>
                <button onClick={incrementHandle}>累加</button>
                <button onClick={decrementHandle}>累减</button>
                <button onClick={ifOddIncrementHandle}>如果是奇数再加1</button>
                <button onClick={waitIncrementHandle}>等2s再加1</button>
            </div>
        </div>
    )
}